package com.cloudera;

import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;

/**
 * Created by shuyun on 2016/10/26.
 */
public class CharLength extends UDF {
    /**
     * 计算字符长度
     * @param content
     * @return
     * @throws UDFArgumentException
     */
    public IntWritable evaluate(Text content) throws UDFArgumentException {
        if(null == content) return new IntWritable(0);

        String contentStr = content.toString();

        return new IntWritable(contentStr.length());
    }
}
